﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.SharePoint;

namespace Slam
{
	public class SlamSettings
	{
		private static Dictionary<string, Hashtable> _settings;
		private string _siteCollectionUrl;

		public Hashtable Settings
		{
			get
			{
				return _settings[_siteCollectionUrl];
			}
		}
		
		public SlamSettings(string siteCollectionUrl)
		{
			_siteCollectionUrl = siteCollectionUrl;
			if (!_settings.ContainsKey(siteCollectionUrl))
			{
				_settings.Add(siteCollectionUrl, new Hashtable());
				SPSecurity.RunWithElevatedPrivileges(delegate() 
				{
					using (SPSite siteCollection = new SPSite(siteCollectionUrl))
					{
						using (SPWeb rootWeb = siteCollection.RootWeb)
						{
							foreach (KeyValuePair<string, object> property in rootWeb.AllProperties)
							{
								if (property.Key.StartsWith("slam"))
								{
									_settings[siteCollectionUrl].Add(property.Key, property.Value);
								}
							}
						}
					}
				});
			}
		}

		public static void ResetSettings()
		{
			_settings.Clear();
		}
	}
}
